package org.ykh.srb.feign.oss;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.ykh.service.result.Result;
import org.ykh.srb.feign.oss.pojo.dto.OssCallbackDto;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Map;

/**
 * @author ykh
 */
@FeignClient("service-oos")
public interface OosApi {

    @PostMapping(value = "/callback", consumes = {MediaType.APPLICATION_FORM_URLENCODED_VALUE})
    Result<?> respond_form(HttpServletRequest request, HttpServletResponse response,
                           @RequestHeader("content-length") Integer contentLength,
                           @RequestHeader("Authorization") String authorization,
                           @RequestHeader("x-oss-pub-key-url") String pubKeyInput,
                           OssCallbackDto ossCallbackDto
    ) throws IOException,
            URISyntaxException;

    @PostMapping(value = "/callback", consumes = {MediaType.APPLICATION_JSON_VALUE})
    Result<?> respond_json(HttpServletRequest request, HttpServletResponse response,
                                  @RequestHeader("content-length") Integer contentLength,
                                  @RequestHeader("Authorization") String authorization,
                                  @RequestHeader("x-oss-pub-key-url") String pubKeyInput,
                                  @RequestBody OssCallbackDto ossCallbackDto
    ) throws IOException,
            URISyntaxException;

    @PostMapping("/upload")
    Result<?> upload(@RequestParam("file") MultipartFile multipartFile) throws IOException;

    @GetMapping("/policy")
    Result<Map<String, String>> policy();


}
